<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <style>
        .hd-form-upload {
            width: 80px;
            height: 80px;
            display: inline-block;
            cursor: pointer;
        }

        .hd-form-upload input {
            display: none;
        }

        .hd-form-upload span {
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            float: left;
            overflow: hidden;
            background-color: #ddd;
        }

        .hd-form-upload span img {
            width: 100%;
            display: inline;
            vertical-align: middle;
        }

        .hd-form-upload span i {
            width: 80px;
            height: 80px;
            float: left;
            position: relative;
        }

        .hd-form-upload  span i:before {
            content: "";
            border-top: 2px solid #bbb;
            position: absolute;
            top: 39px;
            left: 20px;
            right: 20px;
        }

        .hd-form-upload  span i:after {
            content: "";
            border-right: 2px solid #bbb;
            position: absolute;
            top: 20px;
            left: 39px;
            bottom: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">课程标题*</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" placeholder="请输入课程标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Title(EN)*</label>
                <div class="layui-input-block">
                    <input type="text" name="e_title" lay-verify="required" placeholder="请输入Title(EN)" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">课程评价截止时间</label>
                <div class="layui-input-block">
                    <input type="text" name="deadline" placeholder="课程评价截止时间，单位（天），不填写默认为30天（课程结束后开始计算）" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">可见范围</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type">
                        <option value="1">全员可见</option>
                        <option value="2">指定可见</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item range" style="display: none;">
                <label class="layui-form-label">是否进入推荐引擎</label>
                <div class="layui-input-block">
                    <input type="radio" name="range" value="1" title="是" checked>
                    <input type="radio" name="range" value="2" title="否">
                </div>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux">(<span style="color: red;">进入推荐引擎的课允许用户自主注册</span>)</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">课程封面*</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload" id="image">
                        <span id="thumb-img-thumb">
                            <i></i>
                        </span>
                    </label>
                    <input type="hidden" id="img_thumb" name="thumb" value=""/>
                </div>
            </div>
            <div class="layui-input-block">
                <div class="layui-form-mid layui-word-aux">封面图尺寸为16:9</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">线上商城分类</label>
                <div class="layui-input-block">
                    <select name="cate" xm-select="select4" xm-select-skin="default">
                        {volist name="data" id="vo"}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">课程说明*</label>
                <div class="layui-input-block">
                    <textarea name="content" id="content" class="layui-textarea"></textarea>
                </div>
            </div>
            {:token_field()}
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['form', 'jquery', 'element', 'select', 'tinymce', 'upload', 'croppers'], function() {
        let form = layui.form;
        let select = layui.select;
        let tinymce = layui.tinymce;
        let upload = layui.upload;
        let croppers = layui.croppers;
        let $ = layui.jquery;

        var description = tinymce.render({
            elem: "#content",
            height: 400,
            images_upload_url: "{:url('Pub/blob')}",
            form: {name:'file'}
        });


        croppers.render({
            elem: '#image'
            //,saveW:750     //保存宽度
            //,saveH:768
            ,mark:16/9   //选取比例
            ,area:'850px'  //弹窗宽度
            //,url: "https://apilearningsparkminiapp-uat.lorealchina.com/Upload/blob"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            ,url: "{:url('Pub/blob')}"
            ,done: function(url){ //上传完毕回调
                $("#thumb-img-thumb").html('<img src="'+ url + '" />');
                $("#img_thumb").val(url);
            }
        });

        form.on('select(type)', function(data){
            if (data.value == 2) {
                $('.range').css('display','block')
            } else {
                $('.range').css('display','none')
            }
        });
        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            var content = description.getContent();
            data.field.content = '';
            data.field.content += content;
            $.ajax({
                url: '/Learning/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>